package com.ftg.learn.util;

import lombok.Data;

import java.util.Collections;

/**
 * 这个类用来封装前后台交互时所生成的基本格式。
 * @author Guo
 * @date 2022/2/8
 */
@Data
public class ResEntity {

    private int code;

    private String msg;

    private Object data;

    public ResEntity(){

    }

    public ResEntity(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public ResEntity OK(String msg,Object data){
        return new ResEntity(0,msg, Collections.emptyMap());
    }

    public ResEntity OK(){
        return new ResEntity(0,"success",Collections.emptyMap());
    }

    public ResEntity OK(Object data){
        return new ResEntity(0,"success",data);
    }

    public ResEntity Failure(String msg,Object data){
        return new ResEntity(-1,msg,data);
    }

    public ResEntity Failure(){
        return new ResEntity(-1,"failure",Collections.emptyMap());
    }



}
